package com.tsingteng.cosfun.ui.mine;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.base.BaseFragment;
import com.tsingteng.cosfun.bean.LabelBean;
import com.tsingteng.cosfun.ui.cosfun.contract.PersonLabelContract;
import com.tsingteng.cosfun.ui.cosfun.presenter.PersonLabelPresenter;
import com.tsingteng.cosfun.utils.LogonUtils;
import com.tsingteng.cosfun.widget.RadarView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class LableDetailFragment extends BaseFragment implements PersonLabelContract.IPersonLabelrView {
    @BindView(R.id.actorTag)
    TextView actorTag;
    @BindView(R.id.layout1)
    LinearLayout layout1;
    @BindView(R.id.actorTag1)
    TextView actorTag1;
    @BindView(R.id.actorTag2)
    TextView actorTag2;
    @BindView(R.id.actorTag3)
    TextView actorTag3;
    @BindView(R.id.actorTag4)
    TextView actorTag4;
    @BindView(R.id.audienceTag)
    TextView audienceTag;
    @BindView(R.id.audienceTag1)
    TextView audienceTag1;
    @BindView(R.id.audienceTag2)
    TextView audienceTag2;
    @BindView(R.id.audienceTag3)
    TextView audienceTag3;
    @BindView(R.id.audienceTag4)
    TextView audienceTag4;
    @BindView(R.id.commentTag)
    TextView commentTag;
    @BindView(R.id.commentTag1)
    TextView commentTag1;
    @BindView(R.id.commentTag2)
    TextView commentTag2;
    @BindView(R.id.commentTag3)
    TextView commentTag3;
    @BindView(R.id.commentTag4)
    TextView commentTag4;
    @BindView(R.id.directorTag)
    TextView directorTag;
    @BindView(R.id.directorTag1)
    TextView directorTag1;
    @BindView(R.id.directorTag2)
    TextView directorTag2;
    @BindView(R.id.directorTag3)
    TextView directorTag3;
    @BindView(R.id.directorTag4)
    TextView directorTag4;
    @BindView(R.id.screenwriterTag)
    TextView screenwriterTag;
    @BindView(R.id.screenwriterTag1)
    TextView screenwriterTag1;
    @BindView(R.id.screenwriterTag2)
    TextView screenwriterTag2;
    @BindView(R.id.screenwriterTag3)
    TextView screenwriterTag3;
    @BindView(R.id.screenwriterTag4)
    TextView screenwriterTag4;
    private PersonLabelPresenter personLabelPresenter;
    private ProgressBar progressBar1, progressBar2, progressBar3, progressBar4, progressBar5;
    private RadarView radarView;
    private final float MAX = 3f;
    private long userId;

    @Override
    protected void initView() {
        progressBar1 = rootView.findViewById(R.id.progres1);
        progressBar2 = rootView.findViewById(R.id.progres2);
        progressBar3 = rootView.findViewById(R.id.progres3);
        progressBar4 = rootView.findViewById(R.id.progres4);
        progressBar5 = rootView.findViewById(R.id.progres5);

        radarView = rootView.findViewById(R.id.lable_radarview);
        personLabelPresenter = new PersonLabelPresenter(this);
        if (userId == 0) {
            userId = LogonUtils.getProFildId();
        }
        personLabelPresenter.getLabel(userId);
    }

    @Override
    protected void getBundle(Bundle bundle) {
        if (bundle.containsKey(HomeMineFragment.USERID)) {
            userId = bundle.getLong(HomeMineFragment.USERID);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_lable_layout;
    }

    @Override
    public void getLabel(LabelBean labelBean) {
        if (labelBean == null) {
            return;
        }
        initTextColor(labelBean);
        progressBar1.setProgress((int) (labelBean.actorTag * 100 + labelBean.actorTagDecimal * 100));
        progressBar2.setProgress((int) (labelBean.audienceTag * 100 + labelBean.audienceTagDecimal * 100));
        progressBar3.setProgress((int) (labelBean.commentTag * 100 + labelBean.commentTagDecimal * 100));
        progressBar4.setProgress((int) (labelBean.directorTag * 100 + labelBean.directorTagDecimal * 100));
        progressBar5.setProgress((int) (labelBean.screenwriterTag * 100 + labelBean.screenwriterTagDecimal * 100));

        float[] data = new float[5];
        data[0] = (labelBean.commentTagDecimal);
        data[1] = (labelBean.audienceTagDecimal);
        data[2] = (labelBean.actorTagDecimal);
        data[3] = (labelBean.screenwriterTagDecimal);
        data[4] = (labelBean.directorTagDecimal);
        radarView.setData(data);

    }

    private void initTextColor(LabelBean labelBean) {
        if (labelBean.actorTag < 1) {
            setSelectTextColor(actorTag1);
            setUnSelectTextColor(actorTag2,actorTag3,actorTag4);
        } else if (labelBean.actorTag < 2) {
            setSelectTextColor(actorTag1,actorTag2);
            setUnSelectTextColor(actorTag3,actorTag4);
            if (labelBean.actorTagDecimal<0.8) {
                actorTag.setTextColor(getActivity().getResources().getColor(R.color.color_found));
            }else {
                actorTag.setTextColor(getActivity().getResources().getColor(R.color.black));
            }
        } else if (labelBean.actorTag < 3) {
            setSelectTextColor(actorTag1,actorTag2,actorTag3);
            setUnSelectTextColor(actorTag4);
        } else {
            setSelectTextColor(actorTag1,actorTag2,actorTag3,actorTag4);
        }
        if (labelBean.audienceTag < 1) {
            setSelectTextColor(audienceTag1);
            setUnSelectTextColor(audienceTag3,audienceTag2,audienceTag4);
        } else if (labelBean.audienceTag < 2) {
            if (labelBean.audienceTagDecimal<0.7) {
                audienceTag.setTextColor(getActivity().getResources().getColor(R.color.color_found));
            }else {
                audienceTag.setTextColor(getActivity().getResources().getColor(R.color.black));
            }
            setSelectTextColor(audienceTag1,audienceTag2);
            setUnSelectTextColor(audienceTag3,audienceTag4);
        } else if (labelBean.audienceTag < 3) {
            setSelectTextColor(audienceTag1,audienceTag2,audienceTag3);
            setUnSelectTextColor(audienceTag4);
        } else {
            setSelectTextColor(audienceTag1,audienceTag2,audienceTag3,audienceTag4);
        }
        if (labelBean.commentTag < 1) {
            setSelectTextColor(commentTag1);
            setUnSelectTextColor(commentTag2,commentTag3,commentTag4);
        } else if (labelBean.commentTag < 2) {
            if (labelBean.commentTagDecimal<0.7) {
                commentTag.setTextColor(getActivity().getResources().getColor(R.color.color_found));
            }else {
                commentTag.setTextColor(getActivity().getResources().getColor(R.color.black));
            }
            setSelectTextColor(commentTag1,commentTag2);
            setUnSelectTextColor(commentTag3,commentTag4);
        } else if (labelBean.commentTag < 3) {
            setSelectTextColor(commentTag1,commentTag2,commentTag3);
            setUnSelectTextColor(commentTag4);
        } else {
            setSelectTextColor(commentTag1,commentTag2,commentTag3,commentTag4);
        }
        if (labelBean.directorTag < 1) {
            setSelectTextColor(directorTag1);
            setUnSelectTextColor(directorTag2,directorTag3,directorTag4);
        } else if (labelBean.directorTag < 2) {
            if (labelBean.directorTagDecimal<0.7) {
                directorTag.setTextColor(getActivity().getResources().getColor(R.color.color_found));
            }else {
                directorTag.setTextColor(getActivity().getResources().getColor(R.color.black));
            }
            setSelectTextColor(directorTag1,directorTag2);
            setUnSelectTextColor(directorTag3,directorTag4);
        } else if (labelBean.directorTag < 3) {
            setSelectTextColor(directorTag1,directorTag2,directorTag3);
            setUnSelectTextColor(directorTag4);
        } else {
            setSelectTextColor(directorTag1,directorTag2,directorTag3,directorTag4);
        }
        if (labelBean.screenwriterTag < 1) {
            setSelectTextColor(screenwriterTag1);
            setUnSelectTextColor(screenwriterTag2,screenwriterTag3,screenwriterTag4);
        } else if (labelBean.screenwriterTagDecimal < 2) {
            if (labelBean.screenwriterTagDecimal<0.7) {
                screenwriterTag.setTextColor(getActivity().getResources().getColor(R.color.color_found));
            }else {
                screenwriterTag.setTextColor(getActivity().getResources().getColor(R.color.black));
            }
            setSelectTextColor(screenwriterTag1,screenwriterTag2);
            setUnSelectTextColor(screenwriterTag3,screenwriterTag4);
        } else if (labelBean.screenwriterTag < 3) {
            setSelectTextColor(screenwriterTag1,screenwriterTag2,screenwriterTag3);
            setUnSelectTextColor(screenwriterTag4);
        } else {
            setSelectTextColor(screenwriterTag1,screenwriterTag2,screenwriterTag3,screenwriterTag4);
        }
    }


    public void setUnSelectTextColor(TextView... views) {
        for (int i = 0; i < views.length; i++) {
            views[i].setTextColor(getActivity().getResources().getColor(R.color.white_alpha_40));
        }
    }

    public void setSelectTextColor(TextView... views) {
        for (int i = 0; i < views.length; i++) {
            views[i].setTextColor(getActivity().getResources().getColor(R.color.white));
        }
    }


    @Override
    public void showLoading(String msg) {
        showLoadingDialog();
    }

    @Override
    public void hideLoading() {
        hideLoadingDialog();
    }

    @Override
    public void showFail(String msg) {

    }

    @Override
    public void showError() {

    }

    @Override
    public void showEmpty() {

    }



}
